import static org.quartz.JobBuilder.*
import static org.quartz.TriggerBuilder.*

import org.quartz.CronScheduleBuilder
import org.quartz.CronTrigger
import org.quartz.JobDetail
import org.quartz.Scheduler
import org.quartz.SchedulerFactory
import org.quartz.impl.StdSchedulerFactory

import ar.com.agea.processes.alert.Constants
import ar.com.agea.processes.alert.job.AlertNotificationJob

class BootStrap {

	def grailsApplication

	def init = { servletContext ->

		SchedulerFactory sf = new StdSchedulerFactory();
		Scheduler sched = sf.getScheduler();

		JobDetail job = newJob(AlertNotificationJob.class)
				.withIdentity("job-alertNotifier-monthly", "group1")
				.build();

		job.getJobDataMap().put("nameJob", Constants.NAME_JOB_M);
		job.getJobDataMap().put("intervalCode", Constants.INTERVAL_CODE_MONTHLY);
				
		CronTrigger trigger = newTrigger()
				.withIdentity("trigger1", "group1")
				.withSchedule(CronScheduleBuilder.cronSchedule(grailsApplication.config.cronExpression.monthly))
				.build();

		sched.scheduleJob(job, trigger);
		sched.start()
	}

	def destroy = {
	}
}
